package com.news.news.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.news.news.dao.NewsTypeDao;
import com.news.news.dao.RoleDao;
import com.news.news.modle.Menu;
import com.news.news.modle.NewsType;
import com.news.news.modle.Role;
import com.news.news.util.JWTUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * Created by 罗铠威 on 2023/8/29 16:21
 * type:
 */
@Service
@Transactional
public class NewsTypeService {

    @Resource
    NewsTypeDao newsTypeDao;


    public PageInfo<NewsType> NewsTypeList(@RequestBody NewsType newsType) {
        PageHelper.startPage(newsType.getPageNum(),newsType.getPageSize());
        ArrayList<NewsType> newsTypes = newsTypeDao.newsTypeList(newsType);
//        System.out.println(roles);
        PageInfo<NewsType> pageInfo = new PageInfo<>(newsTypes);
        return pageInfo;
    }

    public void savenewsType(NewsType newsType, String token) {
        newsType.setAdminid(JWTUtil.getTokenInfo(token).getClaim("id").asInt());
        //保存
        newsTypeDao.savenewsType(newsType);

    }

    public void UpdateNewsTypeState(NewsType newsType) {
        newsTypeDao.UpdateNewsTypeState(newsType);
    }

    public NewsType findNewsTypeById(Integer id) {
       return newsTypeDao.findNewsTypeById(id);
    }

    public void updateNewsType(NewsType newsType, String token) {
        newsType.setAdminid(JWTUtil.getTokenInfo(token).getClaim("id").asInt());
        //修改后保存
        newsTypeDao.updateNewsType(newsType);
    }

    public void deleteNewsTypeById(Integer id) {
        newsTypeDao.deleteNewsTypeById(id);
    }
}
